

function say() {
    alert("LC:731. 我的日程安排表 II");
}
say();


var MyCalendarTwo = function() {
    //12:50-05
    this.calender = []
    this.double = []
};

/**
 * @param {number} start
 * @param {number} end
 * @return {boolean}
 */
MyCalendarTwo.prototype.book = function(start, end) {
    var double = this.double
    for(var i = 0; i < double.length; i++){
        var item = double[i]
        
        // console.log('item',item,'s',start,'e',end)
        if(start >= item[0] && start < item[1]){
            return false
        }else if(end > item[0] && end <= item[1]){
            return false
        }else if(start >= item[0] && end <= item[1]){
            return false
        }else if(start < item[0] && end > item[1]){
            return false
        }

        // if(start < item[1] && end > item[0]){
        //     return false
        // }
    }

    var calender = this.calender
    for(var i = 0; i < calender.length; i++){
        var item = calender[i]
        if(start < item[1] && end > item[0]){
            var arr = [Math.max(start,item[0]), Math.min(end, item[1])]
            double.push(arr)
        }
    }
    calender.push([start, end])
    return true
};

/**
 * Your MyCalendarTwo object will be instantiated and called as such:
 * var obj = new MyCalendarTwo()
 * var param_1 = obj.book(start,end)
 */
